package edu.polsl.bio.tools.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * //todo class description
 * <p/>
 * Created on: Aug 31, 2010 4:26:20 PM <br/>
 * <a href="http://www.polsl.pl">www.polsl.pl</a>
 *
 * @author lukasz.olczak@polsl.pl
 */
public class Utils {
  /**
   * slf4j Logger.
   */
  private static final Logger log = LoggerFactory.getLogger(Utils.class.getName());

  public static int max(int a, int b, int c) {
    int max = a;
    if (b > max) max = b;
    if (c > max) max = c;
    return max;
  }

  public static int[] maxIndex(int a, int b, int c) {
    int index = 0;
    int max = a;
    if (b > max) {
      max = b;
      index = 1;
    }
    if (c > max) {
      max = c;
      index = 2;
    }
    return new int[]{max, index};
  }

  public static String reverseDna(String seq) {
    char[] dna = seq.toCharArray();
    char[] reverse = new char[dna.length];

    for (int i = 0; i < dna.length; i++) {
      char nucleo = dna[dna.length - 1 - i];
      char rev;
      switch (nucleo) {
        case 'a':
          rev = 't';
          break;
        case 't':
          rev = 'a';
          break;
        case 'c':
          rev = 'g';
          break;
        case 'g':
          rev = 'c';
          break;
        case 'A':
          rev = 'T';
          break;
        case 'T':
          rev = 'A';
          break;
        case 'C':
          rev = 'G';
          break;
        case 'G':
          rev = 'C';
          break;
        default:
          rev = nucleo;
          break;
      }
      reverse[i] = rev;
    }
    return String.valueOf(reverse);
  }
}
